<template>
  <div class="login_container">
    <h1 style="padding-top: 100px">快泽网络后台管理系统</h1>
    <el-card class="box-card login_box">
      <div slot="header" class="clearfix" style="text-align: center;">
        <h3>登录</h3>
      </div>
      <el-form :model="loginForm" ref="loginFormRef" label-width="100px" class="demo-dynamic">
        <el-form-item
          prop="username"
          label="用户名"
          :rules="[
      { required: true, message: '请输入用户名', trigger: 'blur' },
    ]"
        >
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item
          prop="password"
          label="密码"
          :rules="[
      { required: true, message: '请输入密码', trigger: 'blur' },
    ]"
        >
          <el-input v-model="loginForm.password" type="password"></el-input>
        </el-form-item>
        <el-button type="primary" @click="submitForm('loginFormRef')">登录</el-button>
      </el-form>
    </el-card>
    <div class="footer">
      <p style="background:none;height: 5%;position: fixed;bottom: 0px;width: 100%;text-align: center;
">Copyright ©2021 kuaizewangluo. All rights reserved.
        <a style="color:#000;text-decoration: none;"
           href="https://beian.miit.gov.cn"
           target="_blank">豫ICP备2021029086号</a></p>
    </div>
  </div>
</template>

<script>

import loginService from '@/global/service/loginService';

export default {

  data() {
    return {
      loginForm: {},
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          loginService.login({
            username: this.loginForm.username,
            password: this.loginForm.password,
          }).then((res) => {
            this.$message.success('login successfully')
            localStorage.setItem('token', res.token)
            this.$router.push({
              path: '/',
            })
          })
        }
      });
    },
  },
}
</script>

<style scoped>
.login_container {
  background-color: #42b983;
  width: 100%;
  height: 880px;
  position: relative;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.avatar_box {
  height: 130px;
  width: 130px;
  border: 1px solid #eee;
  border-radius: 50%;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  padding: 10px;
}

img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #eee;
}

h2 {
  padding-top: 40px;
}
</style>
